package cn.e4j.modular.api.controller;

import cn.digiwin.wx.utils.CookieUtils;
import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.util.ToolUtil;
import cn.e4j.modular.api.service.GwaService;
import cn.e4j.modular.api.service.WXUserService;
import cn.e4j.modular.api.util.ControllerSupport;
import cn.e4j.modular.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wenchuan on 2017/6/15.
 */
@RestController
@RequestMapping("api/wx/user")
public class UserController extends ControllerSupport {

    @Autowired
    private WXUserService userService;

    @Autowired
    private GwaService gwaService;

//    /**
//     * 验证当前微信登录用户
//     * 如果已经存在且通过审核
//     * 更新系统cookie
//     *
//     * @return
//     */
//    @RequestMapping(value = "validateUser")
//    public ResponseData validateUser(HttpServletResponse response,HttpServletRequest req,@DtoParam DtoWapper wapper) {
//        Dto outDto = new Dto();
//        Dto inDto = wapper.getDto();
//        inDto.put("GWAAACTI", "Y");
//        inDto.put("DBC", "SP2");
//        Dto authUser = userService.getUserData(inDto);
//        Boolean flag = Boolean.FALSE;
//        if (authUser != null) {
//            String GWAA09 = authUser.getString("GWAA09");
//
//            Map<String, String> prams = new HashMap<>();
//            prams.put("_WX_ACTI_", "Y");
//            prams.put("_WX_CUSCODE_", ToolUtil.isEmpty(GWAA09) ? "00100001" : GWAA09);
//            CookieUtils.setCookie(req,response, prams);
//            flag = Boolean.TRUE;
//        }
//        outDto.put("flag", flag);
//        return SUCCESS(outDto);
//    }


    /**
     * 获取用户列表数据
     *
     * @return
     */
    @RequestMapping(value = "getUserList")
    public ResponseData getUserList(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<>();
        try {
            inDto.put("GWAAENT", inDto.getString("ENT"));
            inDto.put("GWAAACTI", inDto.getString("status"));
            list = userService.getUserList(wapper.getPage(),inDto);
        } catch (Exception ex) {
            ex.printStackTrace();
            return ERROR;
        }
        return SUCCESS(list);
    }



}
